var token = "no";

function getUserInfo() {
    $.ajax({
        url: "/apis/user/loginByToken",
        type: "POST",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        headers: {
            token: token //这里是Token
        },
        cache: false,//设置不缓存
        success: getUserSuccess,
        error: showErrorInfo
    });
    return false;
}

function getUserSuccess(data){
        if(!data.flag) {
            window.location.href = "../index.html";
            alert("请先登录！");
        } else {
            var user = JSON.parse(data.msg);
            userName = user['name'];
            role = user['role'];
            if (role.indexOf("教师") == 0){
                //加载username
                str = "<a href=\"javascript:;\" id=\"userName\" name='"+ user.id+"'>"+userName+"</a>";
                document.getElementById("userName").innerHTML = str;

            }
            else{
                //权限不够
                alert("没有权限！");
                window.location.href = "../index.html";
            }
}
}

$(document).ready(function () {
        token = getCookie("token");
        getUserInfo();
    }
);



